package com.authenticateCenter.service.impl;

import com.authenticateCenter.domain.entity.User;
import com.authenticateCenter.domain.entity.UserRole;
import com.authenticateCenter.mapper.UserMapper;
import com.authenticateCenter.service.IUserRoleService;
import com.authenticateCenter.service.IUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 大忽悠
 * @since 2022年10月08日
 */
@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Override
    public void removeUser(Integer uid, IUserRoleService iUserRoleService) {
        removeById(uid);
        iUserRoleService.remove(new QueryWrapper<UserRole>().eq("uid",uid));
    }

    @Override
    public void enableOrDisableUser(Integer uid, Boolean enableOrDisable) {
        //启用用户
        if(Boolean.TRUE.equals(enableOrDisable)){
            updateById(User.builder().id(uid).enabled(1).build());
            return;
        }
        updateById(User.builder().id(uid).enabled(0).build());
    }
}
